<?php


namespace App\Admin\Actions;


use App\Lead;
use App\Project;
use App\User;
use Encore\Admin\Actions\BatchAction;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;

class TransferLead extends  BatchAction
{
    public $name = '批量复制线索';

    public function handle(Collection $collection,Request $request)
    {
        $project_id=  $request->get('project_id');
        $user_id= $request->get('id');
        foreach ($collection as $model) {
            $newModel=$model->replicate();

                $newModel->owner_user_id=$user_id;
                $newModel->is_transform=0;
                $newModel->customer_id=0;
                $newModel->next_time=0;
                $newModel->follow='待跟进';
                $newModel->create_time=time();
                $newModel->project_id=$project_id;
                $newModel->status='潜在客户';
                $newModel->save();

        }
        return $this->response()->success('复制成功')->refresh();
    }

    public function form()
    {

        $this->select('project_id', '请选择复制的项目')->options(Project::getSelectOptions())->rules('required');
        $this->select('id', '请选择复制的负责人')->options(User::getSelectOptions())->rules('required');

    }
}
